package cn.icanci.loopstack.bic.biz.dts.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.bic.biz.dts.DTS;
import cn.icanci.loopstack.bic.biz.dts.GraphDtsService;
import cn.icanci.loopstack.bic.biz.service.NodeVueService;
import cn.icanci.loopstack.bic.biz.utils.TemplateFileUtils;
import cn.icanci.loopstack.bic.common.enums.NodeVueTypeEnum;
import cn.icanci.loopstack.bic.common.model.base.NodeVO;
import cn.icanci.loopstack.bic.common.model.base.NodeVueVO;

/**
 * @author icanci
 * @since 1.0 Created in 2023/09/20 19:54
 */
@Service
@DTS(NodeVO.class)
public class NodeDtsServiceImpl implements GraphDtsService<NodeVO> {
    private static final String DEFAULT_NAME           = "系统默认";
    private static final String DEFAULT_KEY            = "DEFAULT_KEY";
    private static final String DEFAULT_PLUGIN_CONTEXT = "{}";
    @Resource
    private NodeVueService      nodeVueService;

    @Override
    public void dtsUnitViewTree(NodeVO node) {
        // 插入组件信息
        nodeVueService.save(buildNodeVue(node));
    }

    private NodeVueVO buildNodeVue(NodeVO node) {
        NodeVueVO nodeVue = new NodeVueVO();
        nodeVue.setSystemUuid(node.getSystemUuid());
        nodeVue.setNodeUuid(node.getUuid());
        nodeVue.setNodeVueName(DEFAULT_NAME);
        nodeVue.setNodeVueKey(DEFAULT_KEY);
        nodeVue.setNodeVueCode(TemplateFileUtils.queryDefaultNodeVue());
        nodeVue.setNodeVueType(NodeVueTypeEnum.DIALOG);
        nodeVue.setPluginContext(DEFAULT_PLUGIN_CONTEXT);
        return nodeVue;
    }
}
